/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import interfaces.InternationalizableEntity;
import interfaces.InternationalizableEntityDescription;
import java.io.Serializable;
import java.util.List;
import java.util.Locale;
import javax.faces.context.FacesContext;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author damfercer
 */
@Entity
@Table(name = "job_duration")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "JobDuration.findAll", query = "SELECT j FROM JobDuration j ORDER BY j.value"),
    @NamedQuery(name = "JobDuration.findByIdJobDuration", query = "SELECT j FROM JobDuration j WHERE j.idJobDuration = :idJobDuration"),
    @NamedQuery(name = "JobDuration.findByDescription", query = "SELECT j FROM JobDuration j WHERE j.description = :description"),
    @NamedQuery(name = "JobDuration.findByValue", query = "SELECT j FROM JobDuration j WHERE j.value = :value")})
public class JobDuration implements Serializable, InternationalizableEntity, Comparable<JobDuration> {
    @OneToMany(mappedBy = "minimumJobDuration", fetch = FetchType.LAZY)
    private List<SearchProfessionalInfoRequerimentOrOperator> searchProfessionalInfoRequerimentOrOperatorList;
    @OneToMany(mappedBy = "minimumJobDuration", fetch = FetchType.LAZY)
    private List<SearchProfessionalInfoRequerimentAndOperator> searchProfessionalInfoRequerimentAndOperatorList;
    @OneToMany(mappedBy = "professionalInfoMinimumJobDuration", fetch = FetchType.LAZY)
    private List<Search> searchList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "jobDuration", fetch = FetchType.LAZY)
    private List<CandidateProfessionalInfo> candidateProfessionalInfoList;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_JOB_DURATION")
    private Integer idJobDuration;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 30)
    @Column(name = "DESCRIPTION")
    private String description;
    @Column(name = "VALUE")
    private Integer value;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "jobDuration", fetch = FetchType.LAZY)
    private List<JobDurationDescription> jobDurationDescriptionList;

    public JobDuration() {
    }

    public JobDuration(Integer idJobDuration) {
        this.idJobDuration = idJobDuration;
    }

    public JobDuration(Integer idJobDuration, String description) {
        this.idJobDuration = idJobDuration;
        this.description = description;
    }

    public Integer getIdJobDuration() {
        return idJobDuration;
    }

    public void setIdJobDuration(Integer idJobDuration) {
        this.idJobDuration = idJobDuration;
    }

    public String getDescription() {
//        String resDescription=description;
//        Locale currentLocale=FacesContext.getCurrentInstance().getViewRoot().getLocale();
//        if(!getJobDurationDescriptionList().isEmpty() && !currentLocale.equals(Locale.ENGLISH)){
//            String localeCode=currentLocale.getLanguage();
//            for(JobDurationDescription cd:getJobDurationDescriptionList()){
//                if(cd.getLanguage().getCode().equals(localeCode)){
//                    resDescription=cd.getDescription();
//                }
//            }
//        }
//        return resDescription;
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getValue() {
        return value;
    }

    public void setValue(Integer value) {
        this.value = value;
    }

    @XmlTransient
    public List<JobDurationDescription> getJobDurationDescriptionList() {
        return jobDurationDescriptionList;
    }

    public void setJobDurationDescriptionList(List<JobDurationDescription> jobDurationDescriptionList) {
        this.jobDurationDescriptionList = jobDurationDescriptionList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idJobDuration != null ? idJobDuration.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof JobDuration)) {
            return false;
        }
        JobDuration other = (JobDuration) object;
        if ((this.idJobDuration == null && other.idJobDuration != null) || (this.idJobDuration != null && !this.idJobDuration.equals(other.idJobDuration))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.JobDuration[ idJobDuration=" + idJobDuration + " ]";
    }

    @XmlTransient
    public List<CandidateProfessionalInfo> getCandidateProfessionalInfoList() {
        return candidateProfessionalInfoList;
    }

    public void setCandidateProfessionalInfoList(List<CandidateProfessionalInfo> candidateProfessionalInfoList) {
        this.candidateProfessionalInfoList = candidateProfessionalInfoList;
    }

    @XmlTransient
    public List<Search> getSearchList() {
        return searchList;
    }

    public void setSearchList(List<Search> searchList) {
        this.searchList = searchList;
    }

    @XmlTransient
    public List<SearchProfessionalInfoRequerimentOrOperator> getSearchProfessionalInfoRequerimentOrOperatorList() {
        return searchProfessionalInfoRequerimentOrOperatorList;
    }

    public void setSearchProfessionalInfoRequerimentOrOperatorList(List<SearchProfessionalInfoRequerimentOrOperator> searchProfessionalInfoRequerimentOrOperatorList) {
        this.searchProfessionalInfoRequerimentOrOperatorList = searchProfessionalInfoRequerimentOrOperatorList;
    }

    @XmlTransient
    public List<SearchProfessionalInfoRequerimentAndOperator> getSearchProfessionalInfoRequerimentAndOperatorList() {
        return searchProfessionalInfoRequerimentAndOperatorList;
    }

    public void setSearchProfessionalInfoRequerimentAndOperatorList(List<SearchProfessionalInfoRequerimentAndOperator> searchProfessionalInfoRequerimentAndOperatorList) {
        this.searchProfessionalInfoRequerimentAndOperatorList = searchProfessionalInfoRequerimentAndOperatorList;
    }

    @Override
    public Integer getId() {
        return getIdJobDuration();
    }

    @Override
    public List<? extends InternationalizableEntityDescription> getDescriptionsList() {
        return getJobDurationDescriptionList();
    }

    @Override
    public int compareTo(JobDuration o) {
        return this.getValue().compareTo(o.getValue());
    }
    
}
